from ev import Command, CmdSet


class CmdSetWild(CmdSet):
    "CmdSet for the lightsource commands"
    key = "lightsource_cmdset"
    priority = 1
    def at_cmdset_creation(self):
        "called at cmdset creation"
        self.add(CmdNorth())
        self.add(CmdWest())
        self.add(CmdEast())
        self.add(CmdSouth())
        self.add(CmdUp())
        self.add(CmdDown())



class CmdDirections(Command):
    """
    This is the template class for all direction commands.

    """
    locks = "cmd:all()"

    def func(self):
        "implements the command."
        caller.msg("Non puoi andare in quella direzione.")

class CmdDown(CmdDirections):
    """
    down

    Usage:
      down

    Go down.

    """
    key = "down"
    aliases = ["d", "giu"]

class CmdEast(CmdDirections):
    """
    east

    Usage:
      east

    Go east.

    """
    key = "east"
    aliases = [ "e", "est"]

    def func(self):
        caller = self.caller
        old_loc = caller.db.wild_loc
        new_loc = list(old_loc)
        new_loc[0] += 1
        new_loc = tuple(new_loc)
        ok = caller.wild_move_to(caller.location, new_loc)
        if not ok:
            caller.msg("Non puoi andare in quella direzione.")
        else:
            caller.msg("Vai verso est.")
            caller.location.msg_contents("%s va' verso est." % caller.name, exclude=caller, wild_loc=old_loc)
            caller.location.msg_contents("%s arriva da ovest." % caller.name, exclude=caller, wild_loc=new_loc)
            caller.execute_cmd('look')

class CmdNorth(CmdDirections):
    """
    north

    Usage:
      north

    Go north.

    """
    key = "north"
    aliases = ["n", "nord"]

    def func(self):
        caller = self.caller
        old_loc = caller.db.wild_loc
        new_loc = list(old_loc)
        new_loc[1] += -1
        new_loc = tuple(new_loc)
        ok = caller.wild_move_to(caller.location, new_loc)
        if not ok:
            caller.msg("Non puoi andare in quella direzione.")
        else:
            caller.msg("Vai verso nord.")
            caller.location.msg_contents("%s va' verso nord." % caller.name, exclude=caller, wild_loc=old_loc)
            caller.location.msg_contents("%s arriva da sud." % caller.name, exclude=caller, wild_loc=new_loc)
            caller.execute_cmd('look')


class CmdSouth(CmdDirections):
    """
    south

    Usage:
      south

    Go south.

    """
    key = "south"
    aliases = ["s", "sud"]

    def func(self):
        caller = self.caller
        old_loc = caller.db.wild_loc
        new_loc = list(old_loc)
        new_loc[1] += +1
        new_loc = tuple(new_loc)
        ok = caller.wild_move_to(caller.location, new_loc)
        if not ok:
            caller.msg("Non puoi andare in quella direzione.")
        else:
            caller.msg("Vai verso sud.")
            caller.location.msg_contents("%s va' verso sud." % caller.name, exclude=caller, wild_loc=old_loc)
            caller.location.msg_contents("%s arriva da nord." % caller.name, exclude=caller, wild_loc=new_loc)
            caller.execute_cmd('look')

class CmdWest(CmdDirections):
    """
    west

    Usage:
      west

    Go west.

    """
    key = "west"
    aliases = ["w", "ovest", "o"]

    def func(self):
        caller = self.caller
        old_loc = caller.db.wild_loc
        new_loc = list(old_loc)
        new_loc[0] += -1
        new_loc = tuple(new_loc)
        ok = caller.wild_move_to(caller.location, new_loc)
        if not ok:
            caller.msg("Non puoi andare in quella direzione.")
        else:
            caller.msg("Vai verso ovest.")
            caller.location.msg_contents("%s va' verso ovest." % caller.name, exclude=caller, wild_loc=old_loc)
            caller.location.msg_contents("%s arriva da est." % caller.name, exclude=caller, wild_loc=new_loc)
            caller.execute_cmd('look')


class CmdUp(CmdDirections):
    """
    up

    Usage:
      up

    Go up.

    """
    key = "up"
    aliases = ["u", "su"]

